package org.jivesoftware.smackx;

import java.util.List;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smackx.packet.SharedGroupsInfo;

public class SharedGroupManager
{
  public static List getSharedGroups(Connection paramConnection)
    throws XMPPException
  {
    SharedGroupsInfo localSharedGroupsInfo = new SharedGroupsInfo();
    localSharedGroupsInfo.setType(IQ.Type.GET);
    PacketCollector localPacketCollector = paramConnection.createPacketCollector(new PacketIDFilter(localSharedGroupsInfo.getPacketID()));
    paramConnection.sendPacket(localSharedGroupsInfo);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from the server.");
    if (localIQ.getType() == IQ.Type.ERROR)
      throw new XMPPException(localIQ.getError());
    return ((SharedGroupsInfo)localIQ).getGroups();
  }
}